<template>
<div>
  <!-- 面包屑 -->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 卡片区域 -->
  <el-card class="box-card">
    <el-form :inline="true" class="demo-form-inline">
      <!-- 搜索框 -->
      <el-form-item>
        <el-input
          placeholder="请输入内容"
          prefix-icon="el-icon-search"
          v-model="queryInfo.query">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getAllOrder">搜索</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格数据 -->
    <el-table
      :data="orderList"
      style="width: 100%"
      border
      stripe>
      <el-table-column
        type="index"
        label="#">
      </el-table-column>
      <el-table-column
        prop="order_number"
        label="订单编号">
      </el-table-column>
      <el-table-column
        prop="order_price"
        label="订单价格">
      </el-table-column>
      <el-table-column
        prop="pay_status"
        label="是否付款">
        <template v-slot="slot_1">
          <el-tag type="warning" v-if="slot_1.row.pay_status == 0">未支付</el-tag>
          <el-tag v-else>已支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="is_send"
        label="是否发货">
        <template v-slot="slot_2">
          <el-tag type="warning" v-if="slot_2.row.level == 1">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="下单时间">
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="mySlot">
          <el-tooltip class="item" effect="dark" content="修改" placement="top">
            <el-button @click="editDialog(mySlot.row.id)" type="primary" icon="el-icon-edit" circle></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="物流信息" placement="top">
            <el-button type="success" icon="el-icon-setting" circle></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <!--分页操作-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[2, 5, 10, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!-- 修改地址操作 -->
    <el-dialog
      title="修改地址"
      v-model="editOrdersVisible"
      width="60%"
      center>
      <el-form :model="updateForm" status-icon ref="updateForm" class="demo-ruleForm" label-width="90px">
        <el-form-item label="省市区/县">
          <el-cascader
            :options="cityOptions"
            :value="city"
            change-on-select
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" >
          <el-input></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
          <span class="dialog-footer">
            <el-button @click="editOrdersVisible = false">取 消</el-button>
            <el-button type="primary" @click="edit">确 定</el-button>
          </span>
      </template>
    </el-dialog>
  </el-card>
</div>
</template>

<script>
import {ElMessage} from "element-plus";
import cityOptions from '../../assets/js/city_data2017_element.js'

export default {
name: "orders",
  data(){
    return {
      orderList:[],
      queryInfo:{
        query:'',
        pagenum:1,
        pagesize:5
      },
      total:0,
      editOrdersVisible:false,
      updateForm:[],
      city:[],
      cityOptions: cityOptions,
    }
  },
  created() {
    this.getAllOrder();
  },
  methods:{
    //获取所有的订单数据
    getAllOrder(){
      this.axios.get('orders',{
        params:this.queryInfo
      }).then(resp=>{
        console.log(resp);
        if(resp.data.meta.status !== 200) return ElMessage.error(resp.data.meta.msg);
        //有数据了
        this.orderList = resp.data.data.goods;
        //循环修改每一条时间戳
        this.orderList.forEach(item=>{
          this.dateFilter(item);
        })
        this.total = resp.data.data.total;
      }).catch(err=>{
        console.log(err)
      })
    },
    //每一页几条数据
    handleSizeChange(val){
      this.queryInfo.pagesize = val;
      this.getAllOrder();
    },
    //当前第几页
    handleCurrentChange(val){
      this.queryInfo.pagenum = val;
      this.getAllOrder();
    },
    //时间戳过滤器
    dateFilter(item){
      let date = new Date(item.create_time);
      let year = date.getFullYear();
      let month = date.getMonth()+1;
      let day = date.getDate();
      let hours = date.getHours();
      let mine = date.getMinutes();
      let secs = date.getSeconds();
      item.create_time = year+"-"+month+"-"+day+"  "+hours+":"+mine+":"+secs;
    },
    //编辑用户
    editDialog(id){
      this.editOrdersVisible = true;
    },
    edit(){
    }
  },
}
</script>
<style scoped>

</style>
